package com.waimai.log;

import com.waimai.constant.FileConstant;
import com.waimai.controllor.FileControllor;
import com.waimai.utils.DateUtils;

public class Log {
	public static void e(Exception e, String logString) {
		StringBuilder sb = new StringBuilder("[date]:\n");
		sb.append("\t" + DateUtils.getMonth() + "-" + DateUtils.getDate()
				+ "\t" + DateUtils.getHours() + ":" + DateUtils.getMinutes()
				+ ":" + DateUtils.getSeconds() + "\n");
		sb.append("[info]:\n");
		sb.append("\t" + logString + "\n");
		if (e != null) {
			sb.append("[stack]:" + "\tclassName: " + e.getClass() + "\n");
			StackTraceElement[] stackElements = e.getStackTrace();
			if (stackElements != null) {
				for (int i = 0; i < stackElements.length; i++) {
					sb.append("\t" + stackElements[i].getClassName() + ":\t");
					sb.append(stackElements[i].getLineNumber() + " ");
					sb.append(stackElements[i].getMethodName() + "()\n");
				}
			}
		}
		sb.append("---------------------------------------------------");
		sb.append("\n");
		sb.append("\n");
		FileControllor.getInstance().printLog(sb.toString(),
				FileConstant.LOG_ERROR);
	}

	public static void e(String logString) {
		e(null, logString);
	}

	public static void i(String logString) {
		StringBuilder sb = new StringBuilder("[date]:\n");
		sb.append("\t" + DateUtils.getMonth() + "-" + DateUtils.getDate()
				+ "\t" + DateUtils.getHours() + ":" + DateUtils.getMinutes()
				+ ":" + DateUtils.getSeconds() + "\n");
		sb.append("[info]:\n");
		sb.append("\t" + logString + "\n");
		sb.append("---------------------------------------------------\n");
		FileControllor.getInstance().printLog(sb.toString(),
				FileConstant.LOG_INFO);
	}
}
